<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>layui</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
		<link rel="stylesheet" type="text/css" href="/static/manage/common/bootstrap/js/bootstarp-3.3.7/css/bootstrap.min.css" />
		<script src="/static/manage/common/bootstrap/js/jquery-3.2.0.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="/static/manage/common/bootstrap/js/bootstarp-3.3.7/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
		<link rel="stylesheet" type="text/css" href="/static/manage/common/bootstrap/js/bootstarp-table-1.11.1/bootstrap-table.min.css" />
		<script src="/static/manage/common/bootstrap/js/bootstarp-table-1.11.1/bootstrap-table.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="/static/manage/common/bootstrap/js/bootstarp-table-1.11.1/bootstrap-table-zh-CN.min.js" type="text/javascript" charset="utf-8"></script>
		 <!-- <meta http-equiv="refresh" content="8">  -->
	</head>

	<script type="text/javascript">
	
		//转换日期格式(时间戳转换为datetime格式)
		function changeDateFormat(cellval) {
			var dateVal = cellval + "";
			if(cellval != null) {
				var date = new Date(parseInt(dateVal.replace("/Date(", "").replace(")/", ""), 10));
				var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
				var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();

				var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
				var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
				var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();

				return date.getFullYear() + "-" + month + "-" + currentDate + " " + hours + ":" + minutes + ":" + seconds;
			}
		}
		//删除
		function btn_delete(config_id) {
			$.ajax({
				type: "post",
				url: "/big/deleteConfig/" + config_id,
				success: function(data) {
					$("#table").bootstrapTable("refresh");
				}
			});
		}
		//查询
		function addbig() {

			$("#myModal").modal("show");

		}

		//添加
		function fro() {

			$.ajax({
				type: "post",
				url: "/big/add",
				data: $("#fm").serialize(),
				success: function(data) {
					$("#buy_num").val("")
					$("#give_num").val("")
					$("#remark").val("")
					$("#myModal").modal("hide")
					$("#table").bootstrapTable("refresh");
				}
			});
		}

		function reset() {
			$("#fm").reset();
		}

		//通过id然后修改
		function findByTypeId(config_id) {
			alert(config_id)
			$.ajax({
				type: "post",
				url: "/big/upid/" + config_id,

				data: $("#fm2").serialize(),
				success: function(data) {
					$("#config_id1").val(data.config_id);
					$("#buy_num1").val(data.buy_num);
					$("#give_num1").val(data.give_num);
					$("#remark1").val(data.remark);
				}
			})

		}
		
	
	</script>

	<body>
		<p>一元人民币可兑换
			<input type="text" name="param" id="param" value="" disabled="disabled" />个颜值 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 颜值有效期
			<input type="text" name="params" id="params" disabled="disabled" />天
		</p>

		<div class="container-fluid">

			<table id="table">
				<div class="btn-group operation">
					<button type="button" class="btn bg-primary" onclick="addbig()">
				<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
				
				</button>
				<button type="button" class="btn btn-info" id="tyty" data-toggle="modal" data-target="#myModal3"><span class="glyphicon glyphicon-repeat" aria-hidden="true">
					
				</span>&nbsp;修改RMB兑换</button>

				</div>
			</table>

		</div>

		<!-- 添加Modal -->
		<form id="fm">
			<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
				<div class="modal-dialog" role="document">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
							<h4 class="modal-title" id="myModalLabel">新增颜值配置信息</h4>
						</div>
						<div class="modal-body">
							<div class="form-group">
								<label for="exampleInputName2">购买颜值数量：</label>
								<input type="number" class="form-control" id="buy_num" name="buy_num" placeholder="请输入名称">
							</div>
							<div class="form-group">
								<label for="exampleInputName2">赠送颜值数量：</label>
								<input type="number" class="form-control" id="give_num" name="give_num" placeholder="请输入内容">
							</div>
							<div class="form-group">
								<label for="exampleInputName2">备注：</label>
								<input type="text" class="form-control" id="remark" name="remark" placeholder="请输入内容">
							</div>
						</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
							<button type="button" class="btn btn-primary" id="addbtn2" onclick="fro()">保存</button>
						</div>
					</div>
				</div>
			</div>
		</form>
		
		<!-- 修改RMB兑换的Modal -->
		<form id="fm3">
			<div class="modal fade" id="myModal3" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
				<div class="modal-dialog" role="document">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
							<h4 class="modal-title" id="myModalLabel">修改RMB兑换值</h4>
						</div>
						<div class="modal-body">
							<div class="form-group">
								<input type="hidden" class="form-control" id="config_id1" name="config_id" value="">
								<label for="exampleInputName2">一元人民币可兑换的颜值：</label>
								<input type="text" class="form-control" id="exchange_beauty" name="exchange_beauty" value="">
							</div>
							<div class="form-group">
								<label for="exampleInputName2">颜值有效期：</label>
								<input type="text" class="form-control" id="beauty_overtime" name="beauty_overtime" value="">
							</div>
						</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
							<button type="button" class="btn btn-primary" onclick="updatebtn3()">保存</button>
						</div>
					</div>
				</div>
			</div>
		</form>
		
		<!-- 修改Modal -->
		<form id="fm2">
			<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
				<div class="modal-dialog" role="document">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
							<h4 class="modal-title" id="myModalLabel">修改列表</h4>
						</div>
						<div class="modal-body">
							<div class="form-group">
								<input type="hidden" class="form-control" id="config_id1" name="config_id" value="">
								<label for="exampleInputName2">购买颜值：</label>
								<input type="text" class="form-control" id="buy_num1" name="buy_num" value="">
							</div>
							<div class="form-group">
								<label for="exampleInputName2">赠送颜值：</label>
								<input type="text" class="form-control" id="give_num1" name="give_num" value="">
							</div>
							<div class="form-group">
								<label for="exampleInputName2">备注：</label>
								<input type="text" class="form-control" id="remark1" name="remark" value="">
							</div>
						</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
							<button type="button" class="btn btn-primary" id="updatebtn2">保存</button>
						</div>
					</div>
				</div>
			</div>
		</form>

	</body>

	<script type="text/javascript">
	
	function updatebtn3(){
		$.ajax({
			
			type:"post",
			url:"/big/update",
			data:{
				
				exchange_beauty:$("#exchange_beauty").val(),
				beauty_overtime:$("#beauty_overtime").val()
				
				
			},
			success:function(data){
				$("#myModal3").modal("hide");
				window.location.reload();
				alert("修改成功")
			}
		})
	}		
	
		$(document).ready(function() {
			$("#btnDel").click(function() {
				$(":checked").parent().parent().fadeOut("show"); //隐藏所有被选中的input元素
				//parent() 获得当前匹配元素集合中每个元素的父元素,

			})

			$("tr").mousemove(function() {
				$(this).css("background", "#F0F0F0"); //鼠标经过背景颜色变为灰色

			})
			$("tr").mouseout(function() {
				$(this).css("background", "#fff"); //离开后背景颜色回复白色
			})

			//全选
			$("#checkAll").click(function() {

				if($("#checkAll").attr("checked") == false) {

					$("input[name='checkbox']").each(function() {
						$(this).attr("checked", true);
					});
				} else {

					$("input[name='checkbox']").each(function() {
						$(this).attr("checked", false);
					});
				}

			});

			//提交修改
			$("#updatebtn2").click(function() {
				$.ajax({
					type: "post",
					url: "/big/up/",
					data: {
						config_id: $("#config_id1").val(),
						buy_num: $("#buy_num1").val(),
						give_num: $("#give_num1").val(),
						remark: $("#remark1").val()

					},
					success: function(data) {
						$("#myModal2").modal("hide");
						$("#table").bootstrapTable('refresh');
					}
				});

			})
			
			
			
			
			
			
			$("#tyty").click(function(){
				$.ajax({
					type:"get",
					url:"/big/allsysparamKey",
					success:function(data){
						console.log("=="+data.subscribe_deposit.param_value);
						$('#exchange_beauty').val(data.exchange_beauty.param_value);
						$('#beauty_overtime').val(data.beauty_overtime.param_value)
						
					}
				});
			})
			
		});

		$(function() {
			//alert(1321)
				$.ajax({
				type: "post",
				url: "/big/getparam" ,
				success: function(data) {
				//	alert(data.rows.param_value)
					$("#param").val(data.rows.param_value);
				}
			})
			
				
			
				$.ajax({
				type: "post",
				url: "/big/getparams" ,
				success: function(data) {
				//	alert(data.rows.param_name)
					$("#params").val(data.rows.param_value);
				}
			})
				
			$("#table").bootstrapTable({
				url: "/big/list",
				method: 'get',
				//queryParams: queryParams, //模糊查询
				striped: true, //是否显示行间隔色

				locale: 'zh-CN', //中文支持

				pagination: true, //是否开启分页（*）

				pageNumber: 1, //初始化加载第一页，默认第一页

				pageSize: 5, //每页的记录行数（*）

				pageList: [5, 7, 9], //可供选择的每页的行数（*）

				sidePagination: "server", //分页方式：client客户端分页，server服务端分页（*）

				showRefresh: true, //刷新按钮

				//queryParams: oTableInit.queryParams, //传递参数（*）
				striped: true,
				strictSearch: true,

				showColumns: true, //是否显示所有的列

				minimumCountColumns: 2, //最少允许的列数

				clickToSelect: true, //是否启用点击选中行
				clickToSelect: true,

				columns: [{
					title: '序号',
					align: "center",
					width: 40,
					formatter: function(value, row, index) {
						//获取每页显示的数量
						var pageSize = $('#table').bootstrapTable('getOptions').pageSize;
						//获取当前是第几页  
						var pageNumber = $('#table').bootstrapTable('getOptions').pageNumber;
						//返回序号，注意index是从0开始的，所以要加上1
						return pageSize * (pageNumber - 1) + index + 1;
					}
				}, {
					field: "config_id",
					title: "配置编号",
					align: "center"

				}, {
					field: "buy_num",
					title: "购买颜值数量",
					align: "center"
				}, {
					field: "give_num",
					title: "赠送颜值数量",
					align: "center"
				}, {
					field: "remark",
					title: "备注",
					align: "center"
				}, {
					field: "create_time",
					title: "创建时间",
					align: "center",
					formatter: function(value, row, index) {
						return changeDateFormat(value);
					}
				}, {
					field: "modify_time",
					title: "更新时间",
					align: "center",
					formatter: function(value, row, index) {
						return changeDateFormat(value);
					}
				}, {
					title: "操作",
					align: "center",
					formatter: function(value, row, index) {
						return '<button class="btn btn-success" data-toggle="modal" data-target="#myModal2" onclick="findByTypeId(' + row.config_id + ')">修改<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></button>' + '&nbsp&nbsp' + '<button onclick="btn_delete(' + row.config_id + ')" class="btn btn-danger">删除<span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button>'

					},

				}]
			})

		});
	</script>

</html>